<%@page import="syferserver.Container" %>
<%@page import="java.net.Inet4Address" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>SYFeR Chat Client</title>
        <link href="style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div id="fullpage">
        <div class="centered">
        <%
        if(request.getParameter("id") == null){
        %>
        <form action="index.jsp?id=<%= requestNewChannel() %>" method="post">
            <input type="submit" value="New channel" name="new"/>
        </form>
        <%
        }else{
        %>
            <script src="http://dl.javafx.com/1.2/dtfx.js"></script>
            <script>
                javafx(
                    {
                          archive: "SYFeR.jar",
                          draggable: false,
                          width: 380,
                          height: 280,
                          code: "syfer.Main",
                          name: "SYFeR"
                    },{
                          channel_id: "<%= request.getParameter("id") %>",
                          server_ip: "<%= getIP() %>"
                    }
                );
            </script>
        <%
        }
        %>
        </div>
        </div>
    </body>
</html>

<%!
private String requestNewChannel(){
    return Container.addChannel();
}

private String getIP(){
    try{
        return Inet4Address.getLocalHost().getHostAddress();
    }
    catch(Exception e){
        return "127.0.0.1";
    }
}
%>